package bookshop.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import bookshop.beans.CriteriaBook;
import bookshop.beans.Page;
import bookshop.service.BookService;

public class ShowPageServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String pageNo=request.getParameter("pageNo");
		String min=request.getParameter("minPrice");
		String max=request.getParameter("maxPrice");
		CriteriaBook criteriaBook=new CriteriaBook();
		if(pageNo!=null){
			int pageNum=Integer.parseInt(pageNo);
			criteriaBook.setPageNo(pageNum);
		}		
		if(min!=null){
			int minPrice=Integer.parseInt(min);
			criteriaBook.setMinPrice(minPrice);
		}
		if(max!=null){
			int maxPrice=Integer.parseInt(max);
			criteriaBook.setMaxPrice(maxPrice);
		}
		BookService bookservice=new BookService();
		bookservice.getBooksByPrice(criteriaBook);
		bookservice.getTotalNum(criteriaBook);
		Page page=bookservice.getPage();
		request.setAttribute("page",page);	
		request.getRequestDispatcher("/showbooks.jsp").forward(request, response);
	}

}
